<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <canvas id="canvas"></canvas>
    <script>
        // 维护多少列，每列的值初始化为0
        // 每次画一次，每列的值加一个字体的高度
        // 当每列的值大于高度 回归0，要达到不规律下雨，则加一个随机数，每列的值大于某个随机数，也回归0
        let canvas = document.querySelector('canvas');
        canvas.width = screen.availWidth; // 浏览器最大可用宽度，我受缩放影响
        canvas.height = screen.availHeight;// 
        let ctx = canvas.getContext('2d');
        let str = 'abcdefghijklyzobqrstuvwxyz1234567890'.split('');
        let arr = Array(Math.ceil(canvas.width / 10)).fill(0);
        function rain() {
            ctx.fillStyle = 'rgba(0,0,0,0.05)';
            ctx.fillRect(0, 0, canvas.width, canvas.height); // 刷一遍透明黑色，越刷越多时，前面画的内容就看不见了
            ctx.fillStyle = '#0f0';
            arr.forEach((v, i) => {
                ctx.fillText(str[Math.floor(Math.random() * str.length)], i * 10, v)
                arr[i] = v >= canvas.height || v >= Math.random() * 20000 ? 0 : v + 10
            })
        }
        setInterval(rain, 40);
    </script>
</body>

</html>